Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
React-hook-form custom onChange handler en la casilla de verificación -> el cambio no está registrado

Necesitaría agregar un controlador personalizado en el evento onChange de una casilla de verificación, sin embargo, al hacerlo onChange no se reflejará en el formulario de gancho de reacción.

He seguido las instrucciones sobre cómo personalizar onChange siguiendo el capítulo

OnChange personalizado, onBlur : https://react-hook-form.com/api/useform/register/

Sin embargo, no puede hacer que funcione.

Al ver en DevTool, el primer cambio de casilla de verificación se refleja en forma muy bien, sin embargo, el último con un controlador personalizado no lo hace.

 ... const subscribeToNewsLetter = register('subscribeToNewsLetter') ... <div> ​<label> I consent </label> ​<input ​type="checkbox" ​{...register('consent')} //This checkbox without any custom handler works fine ​/> ​</div> ​<div> ​<label>Subscribe to newsletter</label> ​<input ​type="checkbox" ​onChange={(e) => { ​subscribeToNewsLetter.onChange(e); // This needs to do custom stuff in onChange ​handleChange(e); // However doing so ​}} // the change is not registered to hook-form ​onBlur={subscibeToNewLetter.onBlur} ​ref={subscibeToNewLetter.ref} ​/> </div> ...

Lo he estado manipulando aquí, lo que ilustra mejor el problema. https://stackblitz.com/edit/react-hook-form-fiddling-zlnhzs

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes que actualizar la entrada así:

 <input type="checkbox" {...subscibeToNewLetter} onChange={e => { subscibeToNewLetter.onChange(e); handleChange(e); }} />

👉🏻 https://stackblitz.com/edit/react-hook-form-fiddling-g3foaa

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!